FROM golang:1.17-alpine as build
WORKDIR /app/kpt-dtm

COPY . .

RUN mkdir -p ./bin

RUN go env -w GO111MODULE=on && \
    go env -w GOPROXY=https://goproxy.cn,direct && \
    go env -w CGO_ENABLED=0 && \
    go env -w GOARCH=amd64 && \
    go env -w GOOS=linux && \
    go build -o ./bin/kptDtm -ldflags "-X kpt.kptyun.cn:3000/kpt-event/kpt-dtm/pod.appVersion=dtm" main.go


FROM alpine:latest
LABEL name="kpt-dtm" \
description="pt service" \
owner="yiping.xu"

WORKDIR /app/kpt-dtm

RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone

COPY --from=0 /app/kpt-dtm/config/ /app/kpt-dtm/bin/config/
COPY --from=0  /app/kpt-dtm/bin/kptDtm /app/kpt-dtm/bin/kptDtm

EXPOSE 8090
VOLUME ["/app/kpt-dtm/logger","/app/kpt-dtm/bin/config/"]

CMD ["/app/kpt-dtm/bin/kptDtm","crontab"]
